package com.zpark.factory;

import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import java.util.function.Predicate;

/**
 * @PackageName: com.zpark.factory
 * @ClassName: CheckAuthRoutePredicateFactory
 * @Description:
 * @author: RZS
 * @date: 2022/12/6  10:55
 */
@Component
public class CheckAuthRoutePredicateFactory  extends AbstractRoutePredicateFactory<CheckAuthRoutePredicateFactory.Config> {

    public CheckAuthRoutePredicateFactory() {
        super(Config.class);
    }

    public Predicate<ServerWebExchange> apply(Config config) {

        return exchange -> {
                System.err.println("进入了CheckAuthRoutePredicateFactory\t" + config.getName());
                if (config.getName().equals("zhangsan")) {
                    return true;
                }
                return false;
            };
        }

//        return exchange -> {
//            System.err.println("进入了CheckAuthRoutePredicateFactory\t" + config.getName());
//            if (config.getName().equals("zhangsan")) {
//                return true;
//            }
//            return false;
//        };
//    }

    public static class Config {
        private String name;

        public void setName(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }
}
